﻿using System.Windows.Controls;
using HandyControl.Expression.Shapes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;

namespace WpfDemo.Common
{
    public class BindProvider
    {
        static List<Param> GetFirst(List<Param> listParam, string ParaText = "请选择")
        {
            listParam.Insert(0, new Param() { ParaValue = null, ParaText = ParaText });
            return listParam;
        }
        public static void BindRole(ComboBox box, bool first = true, bool Nullable = true)
        {
            var listParam = new List<Param>();
            if (Nullable)
            {
                listParam = GetFirst(listParam);
            }
            if (first)
            {
                box.SelectedIndex = 0;
            }
            listParam.Add(new Param() { ParaValue = "100", ParaText = "管理员" });
            listParam.Add(new Param() { ParaValue = "101", ParaText = "操作员" });
            box.ItemsSource = listParam;
        }

        public static void BindCbx(ComboBox box,List<Param> listParam, bool first = true, bool Nullable = true)
        {
           
            if (Nullable)
            {
                listParam = GetFirst(listParam);
            }
            if (first)
            {
                box.SelectedIndex = 0;
            }         
            box.ItemsSource = listParam;
        }
    }

   

    public class Param
    {
        public string ParaValue { get; set; }
        public string ParaText { get; set; }
    }
}
